package mover;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Point2D;

import extensible.Canvas;

/**
 * A MouseMotionListener and MouseListener disguised as a Mass object
 * so that a spring can be created between a dragged mouse and the closest
 * Mass object to it when pressed
 * @author ga-youngjoung
 *
 */
public class MouseMass extends Mass implements MouseMotionListener, MouseListener  { 
	
	private Canvas myCanvas;
	
	/**
	 * constructor for a mass with dummy instance variables
	 * @param canvas
	 */
	public MouseMass (Canvas canvas) {
		//empty variables
		super(new Point2D.Double(), new Dimension(), Color.black, 0, 0);
		myCanvas = canvas;	
	}

	/**
	 * when mouse is clicked, saves the clicked mover (if there was one
	 * clicked) as the currentMover so that when a button is clicked
	 * which has its own listener, the mover can be removed
	 */
	public void mouseClicked(MouseEvent e) {
		Point2D mouse = myCanvas.getMousePosition();
		mouse.setLocation(e.getX(), e.getY());
		System.out.println("clicked!");
		Mover clickedMover = myCanvas.checkForObjectInPosition(mouse);
		if (clickedMover != null) {
			myCanvas.setCurrentMover(clickedMover);
		}
	}

	/**
	 * sets the mouseInCanvas boolean to true
	 */
	public void mouseEntered(MouseEvent e) {
		myCanvas.setMouseInCanvas(true);
	}

	/**
	 * sets the mouseInCanvas boolean to false
	 */
	public void mouseExited(MouseEvent e) {
		myCanvas.setMouseInCanvas(false);
	}

	public void mousePressed(MouseEvent e) {
		myCanvas.addMouseSpring = true;
	}

	/**
	 * sets the removeMouseSpring boolean to true so the spring can
	 * be removed
	 */
	public void mouseReleased(MouseEvent e) {
		myCanvas.removeMouseSpring = true;
	}

	/**
	 * updates the mass's center
	 */
	public void mouseDragged(MouseEvent e) {
		myCenter = new Point2D.Double(e.getX(), e.getY());
	}

	/**
	 * updates the mass's center
	 */
	public void mouseMoved(MouseEvent e) {
		myCenter = new Point2D.Double(e.getX(), e.getY());
	} 
	
	public void update(Canvas canvas) {
		
	}

}
